using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using labDict.Web.business;
using labDict.Web.common;
using labDict.Web.provider;

namespace labDict.Web.UserControls
{
    public partial class SearchResults : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        public void Page_Init(object sender, System.EventArgs e)
        {
            rpTests.ItemDataBound += new RepeaterItemEventHandler(rpTests_OnItemDataBound);
        }

        public void rpTests_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DataRowView rec = (DataRowView)e.Item.DataItem;
           
            if (rec != null) //Make sure that you have the data.
            {
                HyperLink l1 = (HyperLink)e.Item.FindControl("hlLabTest");
                l1.Text = rec["TEST"].ToString();
                l1.NavigateUrl = "~/ViewEdit.aspx?lid=" + rec["TEST_ID"].ToString();
            }
        }
            
        protected void LoadData()
        {
            //SqlDataReader rdr = LabTestBO.GetLabTests();

            rpTests.DataSource = SQLHelper.GetResult("select * from Test order by TEST ASC");
            rpTests.DataBind();
            
            //dlTests.DataSource = rdr;
            //dlTests.DataBind();
            //rdr.Close();
        }

        protected string DisplayData(DataListItem dliItem, DataField pColumn)
        {
            string strData = null;

            if (dliItem.ItemType != ListItemType.Item
                && dliItem.ItemType != ListItemType.AlternatingItem)
            {
                return null;
            }

            try
            {
                switch (pColumn)
                {
                    case DataField.TestName:
                        strData =
                           "";
                        break;
                    default:
                        strData = "";
                        break;
                }
            }
            catch (Exception e)
            {
                strData = e.Message;
            }

            return strData;
        }

        protected void rpTests_ItemCreated(object sender,
                                            RepeaterItemEventArgs e)
        {
                if (e.Item.ItemType != ListItemType.Item
                && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            try
            {
                if (e.Item.DataItem != null)
                {
                    ;
                }
            }
            catch (Exception ex)
            {
                //Utility.HandleException(Page, ex);
                ;
            }
        }

        protected void dlTests_ItemCreated(object sender,
                                            DataListItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item
                && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            try
            {
                if (e.Item.DataItem != null)
                {

                    /*
                    HyperLink item =
                        (HyperLink)e.Item.FindControl("hlTestItem");
                    
                    if (item != null)
                    {
                        avatar.NavigateUrl = _navigateURL + Encryption.EncodeRijndaelForQueryString(_video.Index.ToString()) + _homePageQS;
                        title.NavigateUrl = _navigateURL + Encryption.EncodeRijndaelForQueryString(_video.Index.ToString()) + _homePageQS;
                    }

                    if (_showVideoCommand)
                    {
                        LinkButton lb =
                            (LinkButton)e.Item.FindControl("lbVideoAction");

                        if (lb != null)
                        {
                            if (_view != View.Favorites)
                            {//Only trigger command event with Favorites

                                lb.PostBackUrl = _navigateURL
                                                    +
                                                    Encryption.
                                                        EncodeRijndaelForQueryString(
                                                        _video.Index.ToString());
                            }
                            lb.Text = _videoCommand;
                            lb.Visible = true;
                        }
                    }
                    if (_showVotesNeeded)
                    {
                        IVideoVote videoVote =
                            Functions.GetVotingResults(_video.Index);

                        Label lbl = (Label)e.Item.FindControl("lblVotesNeeded");
                        if (lbl != null)
                        {
                            lbl.Visible = true;
                        }

                        Literal lit =
                            (Literal)e.Item.FindControl("litVotesNeeded");
                        if (lit != null)
                        {
                            switch (_view)
                            {
                                case View.Voteable:
                                    if (videoVote == null)
                                    {
                                        lit.Text = Resources.Yaaway.NewVideo;
                                    }
                                    else
                                    {
                                        _votesNeeded = _requiredVotes
                                                       -
                                                       videoVote.AcceptedVotes.
                                                           Count
                                                       -
                                                       videoVote.RejectedVotes.
                                                           Count;
                                        if (_votesNeeded > 1)
                                        {
                                            lit.Text =
                                                Resources.Yaaway.VotingStarted;
                                        }
                                        else
                                        {
                                            lit.Text = _votesNeeded.ToString()
                                                       + " "
                                                       +
                                                       Resources.Yaaway.
                                                           VoteNeeded;
                                        }
                                    }
                                    break;
                                case View.VotedOn:
                                    lit.Text = Resources.Yaaway.VotingComplete;
                                    break;
                                default:
                                    break;
                            }
                            lit.Visible = true;
                        }
                    }*/
                }
            }
            catch (Exception ex)
            {
                //Utility.HandleException(Page, ex);
                ;
            }
        }

        #region Nested type: DataField

        protected enum DataField : int
        {
            TestName = 0,
            Title = 1,
            UserId = 2,
            User = 3,
            Runtime = 4,
            Description = 5,
            Category = 6,
            Rating = 7,
            ViewCount = 8,
            State = 9,
            VideoIdArgument = 10,
            Avatar = 11,
            VotingAvatar = 12,
            NavigateURL = 13,
            AltTitle = 14,
            DescriptionToolTip = 15
        }

        #endregion



    }

    
}